package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperCategory;
import com.ruoyi.system.service.ISuperCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品分类Controller
 * 
 * @author xjf
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/product/productCategory")
public class SuperCategoryController extends BaseController
{
    @Autowired
    private ISuperCategoryService superCategoryService;

    /**
     * 查询商品父级分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:category:list')")
    @GetMapping("/fatherList")
    public TableDataInfo fatherList(SuperCategory superCategory)
    {
        List<SuperCategory> list = superCategoryService.selectSuperCategoryFatherList(superCategory);
        return getDataTable(list);
    }


    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperCategory superCategory)
    {
        startPage();
        List<SuperCategory> list = superCategoryService.selectSuperCategoryList(superCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:category:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperCategory superCategory)
    {
        List<SuperCategory> list = superCategoryService.selectSuperCategoryList(superCategory);
        ExcelUtil<SuperCategory> util = new ExcelUtil<SuperCategory>(SuperCategory.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superCategoryService.selectSuperCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('product:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperCategory superCategory)
    {
        return toAjax(superCategoryService.insertSuperCategory(superCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('product:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperCategory superCategory)
    {
        return toAjax(superCategoryService.updateSuperCategory(superCategory));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('product:category:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superCategoryService.deleteSuperCategoryByIds(ids));
    }
}
